import 'package:flutter/material.dart';
/*
* 单选开关和复选框
* */
class Exam_7 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("单选开关和复选框"),
      ),
      body: Centent(),
    );
  }
}

class Centent  extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return SwitchAndCheckBoxTestRoute();
  }
}

class SwitchAndCheckBoxTestRoute extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _SwitchAndCheckBoxTestRouteState();
  }

}

class _SwitchAndCheckBoxTestRouteState extends State<SwitchAndCheckBoxTestRoute>{
  bool _switchSelected = true;//维护单选开关状态
  bool _checkBoxSelected = true;//维护复选框状态
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Column(
      children: <Widget>[
        Switch(
          value: _switchSelected,//开关当前状态
          onChanged: (value){
            //重新构建页面
            setState(() {
              _switchSelected = value;
            });
          },
        ),

        Checkbox(
          value: _checkBoxSelected,//复选框状态
          activeColor: Colors.red,
          onChanged: (value){
            setState(() {
              _checkBoxSelected = value;
            });
          },
        )
      ],
    );
  }

}